package com.mlh.springboot.servlet;

import lombok.extern.slf4j.Slf4j;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @author 缪林辉
 * @date 2024/3/3 20:38
 * @DESCRIPTION
 */
// @WebFilter表示MyFilter是一个过滤器，并注入容器
// urlPatterns = {"/css/*"， "/images/*"}
// 当请求/css/ /images/ 目录资源时需要经过过滤器
// 过滤器放行后，在经过拦截器，拦截器是否拦截要根据拦截器的拦截规则
//@WebFilter(urlPatterns = {"/css/*","/images/*"})
public class MyFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest,
                         ServletResponse servletResponse,
                         FilterChain filterChain) throws IOException, ServletException {
        //为了方便观察过滤器处理的资源，我们输出一个url
        HttpServletRequest request=(HttpServletRequest)servletRequest;
        //System.out.println("过滤器处理的url="+request.getRequestURL());
        // 直接放行
        filterChain.doFilter(servletRequest,servletResponse);
    }
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }
    @Override
    public void destroy() {

    }
}
